﻿using System.Collections.Generic;
using System.Linq;
using PortalWeb.CMS.Core.Entity;
using PortalWeb.CMS.Core.IManager;

namespace PortalWeb.CMS.Business
{
    public partial class AttachmentManager: IAttachmentManager
    {
        public IEnumerable<Attachment> FindList(int? modelId, string owner, string type)
        {
            var attachemts = BaseRepository.Find(a => a.ModelId == modelId);
            if (!string.IsNullOrEmpty(owner))
                attachemts = attachemts.Where(a => a.Owner == owner);
            if (!string.IsNullOrEmpty(type))
                attachemts = attachemts.Where(a => a.Type == type);
            return attachemts;
        }

        public IEnumerable<Attachment> FindList(int modelId, string owner, string type, bool withModelIdNull)
        {
            IEnumerable<Attachment> attachemts;
            if (withModelIdNull)
                attachemts = BaseRepository.Find(a => a.ModelId == modelId || a.ModelId == null);
            else
                attachemts = BaseRepository.Find(a => a.ModelId == modelId);
            if (!string.IsNullOrEmpty(owner))
                attachemts = attachemts.Where(a => a.Owner == owner);
            if (!string.IsNullOrEmpty(type))
                attachemts = attachemts.Where(a => a.Type == type);
            return attachemts;
        }
    }
}
